#include <fstream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

#define Nmax 100011
#define Mmax 200011

vector<int> Leg[Nmax];
int N,M;

int Lung[Nmax];
int Begin,Endin;
int St[Nmax],Size;
int St2[Nmax],Size2;

ifstream F("bf.in");
ofstream G("bf.out");

void BF(int Step,int Endin)
{
	if ( Lung[Endin] ) return;
	
	for (int i=1;i<=Size;++i)
	{
		int Stop=Leg[St[i]].size();
		for (int j=0;j<Stop;++j)
			if ( !Lung[Leg[St[i]][j]] )
			{
				Lung[Leg[St[i]][j]]=Step+1;
				St2[++Size2]=Leg[St[i]][j];
			}
	}
	for (int i=1;i<=Size2;++i) St[i]=St2[i],St2[i]=0;
	for (int i=Size2+1;i<=Size;++i) St[i]=0;
	Size=Size2;
	Size2=0;
	
	BF(Step+1,Endin);
}

int main()
{
	F>>N>>M;
	for (int i=1;i<=M;++i)
	{
		int x,y;
		F>>x>>y;
		Leg[x].push_back(y);
		Leg[y].push_back(x);
	}
	
	F>>Begin>>Endin;
	Lung[Begin]=1;
	St[++Size]=Begin;
	
	BF(1,Endin);
	
	G<<Lung[Endin]-1<<'\n';
}
